package com.goldenKey.admin.controller;

import com.goldenKey.common.pojo.result.R;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.goldenKey.common.pojo.po.Borrow;
import com.goldenKey.admin.service.IBorrowService;

/**
 * @Author: 吃我一钊
 * @Description: 控制层
 * @Date: 2025/02/02
 */
@RestController
@RequestMapping("/borrow")
public class BorrowController {

	@Autowired
	private IBorrowService borrowService;

	/**
	 * 新增数据
	 * @param borrow
	 * @return
	 */
	@PostMapping("/save")
	public R<Void> save(@RequestBody Borrow borrow) {
		borrowService.save(borrow);
		return R.ok();
	}

	/**
	 * 根据id删除
	 * @param borrowId
	 * @return
	 */
	@DeleteMapping("/deleteById/{borrowId}")
	public R<Void> deleteById(@PathVariable("borrowId") Integer borrowId) {
		borrowService.removeById(borrowId);
		return R.ok();
	}

	/**
	 * 根据id修改数据
	 * @param borrow
	 * @return
	 */
	@PutMapping("/updateById")
	public R<Void> updateById(@RequestBody Borrow borrow) {
		borrowService.updateById(borrow);
		return R.ok();
	}

	/**
	 * 根据id查询数据
	 * @param borrowId
	 * @return
	 */
	@GetMapping("/getById/{borrowId}")
	public R<Borrow> getById(@PathVariable("borrowId") Integer borrowId) {
		Borrow borrow = borrowService.getById(borrowId);
		return R.ok(borrow);
	}
	/**
	 * 查询所有数据
	 * @return
	 */
	@GetMapping("/list")
	public R<List<Borrow>> list() {
		List<Borrow> borrowList = borrowService.list();
		return R.ok(borrowList);
	}

}